# -*- encoding:utf-8 -*-
# @Time: 2022/11/24 1:45
# @Author: qiujixian
# @Email: 1253598817@qq.com
# @File: permission.py
# @Software: PyCharm

from rest_framework.permissions import BasePermission
from django.contrib.auth.models import Group

class TeacherPermission(BasePermission):
    def has_permission(self, request, view):
        user = request.user  # 获取到当前发送请求的用户信息
        # 判断当前身份，查询用户是不是老师分组
        gourp = Group.objects.filter(name='老师').first()
        user_groups = user.groups.all()
        return user.is_superuser or gourp in user_groups



